﻿@using Microsoft.AspNetCore.Builder
@using Microsoft.AspNetCore.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Options
@inject IViewLocalizer Localizer
@inject IOptions<RequestLocalizationOptions> LocOptions
@{
	var requestCulture = Context.Features.Get<IRequestCultureFeature>();
	var cultureItems = LocOptions.Value.SupportedUICultures
		.Select(c => new SelectListItem { Value = c.Name, Text = c.DisplayName })
		.ToList();
	var returnUrl = string.IsNullOrEmpty(Context.Request.Path) ? "~/" : $"~{Context.Request.Path.Value}";
}

<div title="@Localizer["Request culture provider:"] @requestCulture?.Provider?.GetType().Name">
    <form id="selectLanguage" asp-controller="Home"
          asp-action="SetLanguage" asp-route-returnUrl="@returnUrl"
          method="post" class="form-inline justify-content-end" role="form">
        <div class="form-group">
            <label asp-for="@requestCulture.RequestCulture.UICulture.Name" class="mr-2">@Localizer["Language:"]</label>
            <select name="culture" onchange="this.form.submit();" class="form-control" asp-for="@requestCulture.RequestCulture.UICulture.Name" asp-items="cultureItems"></select>
        </div>
    </form>
</div>